package com.im.utils;
import org.springframework.util.ReflectionUtils;

/**
 * <p>
 *  自定义异常安全Bean拷贝类
 * </p>
 *
 * @author xainsir
 * @since 2025-02-23
 */
public class BeanUtils {
    private BeanUtils(){}

    private static void handleReflectionException(Exception e) {
        ReflectionUtils.handleReflectionException(e);//处理反射异常
    }
    public static <T> T copyProperties(Object orig, Class<T> destClass) {
        try{
            T dest = destClass.newInstance();
            if(dest==null)return null;
            copyProperties(orig,dest);
            return dest;
        }
        catch (Exception e){
            handleReflectionException(e);
            return null;
        }
    }
    public static void copyProperties(Object orig, Object dest) {
        try{org.springframework.beans.BeanUtils.copyProperties(orig,dest);}
        catch (Exception e){handleReflectionException(e);}
    }
}
